<!--
  -    Copyright (c) 2018-2025, infomng All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without
  - modification, are permitted provided that the following conditions are met:
  -
  - Redistributions of source code must retain the above copyright notice,
  - this list of conditions and the following disclaimer.
  - Redistributions in binary form must reproduce the above copyright
  - notice, this list of conditions and the following disclaimer in the
  - documentation and/or other materials provided with the distribution.
  - Neither the name of the pig4cloud.com developer nor the names of its
  - contributors may be used to endorse or promote products derived from
  - this software without specific prior written permission.
  - Author: infomng
  -->
<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        ref="crud"
        :page.sync="page"
        :data="tableData"
        :permission="permissionList"
        :table-loading="tableLoading"
        :option="tableOption"
        :before-open="beforeOpen"
        @on-load="getList"
        @search-change="searchChange"
        @refresh-change="refreshChange"
        @size-change="sizeChange"
        @current-change="currentChange"
        @row-update="handleUpdate"
        @row-save="handleSave"
        @row-del="handleDel">
<!--        <template slot="menuLeft">
          <el-button
            v-if="permissions.pfoc_pfocprocess_export"
            class="filter-item"
            plain
            type="primary"
            size="small"
            icon="el-icon-download"
            @click="exportExcel">导出
          </el-button>
        </template>-->
        <template slot-scope="scope" slot="menu">
          <el-button v-if="permissions.pfoc_pfocprocess_edit"  type="text"  size="small"  plain @click="editParameter(scope.row)">工序参数</el-button>
          <el-button v-if="permissions.pfoc_pfocprocess_edit" type="text"   size="small" plain  @click="$refs.crud.rowEdit(scope.row,scope.index)">编辑</el-button>
          <el-button v-if="permissions.pfoc_pfocprocess_del" type="text"    size="small" plain  @click="handleDel(scope.row,scope.index)">删除</el-button>
        </template>
      </avue-crud>

      <el-dialog title=""
                 ref="editDiaLog"
                 :visible.sync="parameterDialogVisible"
                 width="60%"
                 lock-scroll
                 custom-class="el-drawer rtl  el-dialog-right"
                 v-if="parameterDialogVisible"
                 :fullscreen="parameterDialogFull">
        <template slot="title">
          <div class="avue-crud__dialog__header">
              <span class="el-dialog__title">
                 {{processName}}-工序参数
              </span>
            <div class="avue-crud__dialog__menu" style="margin-top: -4px;margin-right: 10px;" @click="parameterDialogFull? parameterDialogFull=false: parameterDialogFull=true">
              <i class="el-icon-full-screen"></i>
            </div>
          </div>
        </template>
        <!--参数属性页面-->
        <processparameter ref="parameterRef"  :processId="id" />
        <div slot="footer" class="dialog-footer">
          <el-button @click="parameterDialogVisible = false">取 消</el-button>
        </div>
      </el-dialog>
    </basic-container>
  </div>
</template>

<script>
import { fetchList, addObj, putObj, delObj } from '@/api/pfoc/pfocprocess'
import { tableOption } from '@/const/crud/pfoc/pfocprocess'
import { mapGetters } from 'vuex'
/**引入参数属性页面*/
import processparameter from '@/views/pfoc/processparameter/index'
export default {
  name: 'pfocprocess',
  components: {
      //参数属性页面
      processparameter,
  },
  data() {
    return {
      searchForm: {},
      tableData: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      tableLoading: false,
      tableOption: tableOption,
      parameterDialogVisible:false,//修改页面开关
      parameterDialogFull:false,//修改页面弹窗缩放开关（默认放大）
      id:null,//工序ID
      processName:null,//工序名称

    }
  },
  computed: {
    ...mapGetters(['permissions']),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permissions.pfoc_pfocprocess_add, false),
        delBtn: this.vaildData(this.permissions.pfoc_pfocprocess_del, false),
        editBtn: this.vaildData(this.permissions.pfoc_pfocprocess_edit, false)
      }
    }
  },
  methods: {
    // 列表查询
    getList(page, params) {
      this.tableLoading = true
      fetchList(Object.assign({
        current: page.currentPage,
        size: page.pageSize
      }, params, this.searchForm)).then(response => {
        this.tableData = response.data.data.records
        this.page.total = response.data.data.total
        this.tableLoading = false
      }).catch(() => {
        this.tableLoading = false
      })
    },
    // 删除
    handleDel: function(row, index) {
      this.$confirm('是否确认删除ID为' + row.id, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return delObj(row.id)
      }).then(data => {
        this.$message.success('删除成功')
        this.getList(this.page)
      })
    },
    // 更新
    handleUpdate: function(row, index, done, loading) {
      putObj(row).then(data => {
        this.$message.success('修改成功')
        done()
        this.getList(this.page)
      }).catch(() => {
        loading()
      })
    },
    // 保存
    handleSave: function(row, done, loading) {
      addObj(row).then(data => {
        this.$message.success('添加成功')
        done()
        this.getList(this.page)
      }).catch(() => {
        loading()
      })
    },
    // 每页条数改变事件
    sizeChange(pageSize) {
      this.page.pageSize = pageSize
    },
    // 当前页发生改变事件
    currentChange(current) {
      this.page.currentPage = current
    },
    // 查询事件
    searchChange(form, done) {
      this.searchForm = form
      this.page.currentPage = 1
      this.getList(this.page, form)
      done()
    },
    // 刷新事件
    refreshChange() {
      this.getList(this.page)
    },
    //  导出excel
    exportExcel() {
      this.downBlobFile('/pfoc/pfocprocess/export', this.searchForm, 'pfocprocess.xlsx')
    },
    beforeOpen(done, type) {
      if (["add"].includes(type)) {
        this.$set(this.$refs.crud.tableForm, 'sortOrder', this.page.total+1);
      }
      done();
    },
    editParameter(row){
      this.id = row.id;//工序id
      //打开修改页面
      this.parameterDialogVisible = true;
      //设置编辑默认值
      this.processName=row.processName;
      this.$nextTick(() => {
        //调用修改页面工艺产线查询方法
        this.$refs.parameterRef.refreshChange();
      })
    },
  }
}
</script>
<style scoped>
  /deep/ .el-dialog-right{
    left: 40%;
    position: fixed;
    margin-top: 0!important;
    -webkit-animation: rtl-drawer-in .3s 1ms!important;
    animation: rtl-drawer-in .3s 1ms!important;
  }
  /deep/ .el-dialog.is-fullscreen{
    width: 100%;
    margin-top: 0;
    margin-bottom: 0;
    height: 100%;
    overflow: auto;
    left: 0!important;
  }
  /deep/ .el-dialog__header{
    border-bottom: 1px solid rgb(240, 240, 240);
    padding: 20px 20px!important;
  }
  /deep/ .el-dialog__body{
    height: 100%;
    overflow-y: auto;
  }
</style>

